<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

</head>

<body>
    <!--  <script>
        var arr = [1, 3, 4, 5, 6, 7, 8];    //  
        var arr1 = arr.unshift(11, 44, 445, 66);
        console.log(arr, arr1);

        var arr = [1, 2, 3];
        Array.prototype.unshift1 = function () {
            var arr1 = []; 
            for (var i = 0; i < arguments.length; i++) {
                arr1[arr1.length] = arguments[i];
            }
            for (var j = 0; j < arr.length; j++) {
                arr1[arr1.length] = arr[j];
            }
            arr = arr1;
            return arr1.length;
        }
        arr.unshift1(1, 2, 3)
        // console.log(arr);
        console.log(arr.unshift1(1, 2, 3));
        console.log(arr);
    </script> 
 -->
    <script>
        // 用函数封装一个数组的unshift方法
        // 在数组前面添加一个或多个元素
        var arr = ['d', 'r', 'f', 'g'];
        // var num = 10;
        /*  for (let i = arr.length; i > 0; i--) {
             console.log(arr[i]);
             arr[i] = arr[i - 1];
 
         }ze
         arr[0] = num; */

        /*  var arr1 = [1, 3, 4, 5];
         for (let k = arr.length - 1; k >= 0; k--) {
             for (let i = arr.length; i > 0; i--) {
 
                 arr[i] = arr[i - 1];
 
             }
             arr[0] = arr1[k];
         } */
        function unshift(arr) {
            for (let k = arguments.length - 1; k >= 1; k--) {
                for (let i = arr.length; i > 0; i--) {

                    arr[i] = arr[i - 1];

                }
                arr[0] = arguments[k];
            }
        }
        unshift(arr, 10, 20, 40)
        console.log(arr);
        
    </script>
</body>

</html>